home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume11 / test.el / part01 next >
Encoding:
Text File  |  1987-09-08  |  58.0 KB  |  2,002 lines

  1. Path: uunet!rs
  2. From: rs@uunet.UU.NET (Rich Salz)
  3. Newsgroups: comp.sources.unix
  4. Subject: v11i036:  Test system for GNU Emacs, Part01/03
  5. Message-ID: <1501@uunet.UU.NET>
  6. Date: 10 Sep 87 03:53:05 GMT
  7. Organization: UUNET Communications Services, Arlington, VA
  8. Lines: 1991
  9. Approved: rs@uunet.UU.NET
  10.  
  11. Submitted-by: "Mark A. Ardis" <maa@sei.cmu.edu>
  12. Posting-number: Volume 11, Issue 36
  13. Archive-name: test.el/Part01
  14.  
  15. I am sending you (in 3 parts) a package for GNU Emacs called
  16. "test".  It is designed to help authors of GNU Emacs Lisp packages
  17. test their products.  Some of the features of "test" provide
  18. assistance in constructing tests and testscripts.  Other features
  19. assist in the analysis of the effectiveness of testing.
  20.  
  21. Unfortunately, this package has not been adequately tested itself.  It
  22. is the product of a semester-long project at Wang Institute.  Since
  23. the MSE program is being discontinued, we are forced to distribute
  24. this package prematurely, lest it be lost.  As the instructor of the
  25. course I will be glad to collect comments, suggestions, bug reports,
  26. etc. at my new address:
  27.  
  28. Mark A. Ardis
  29. Software Engineering Institute
  30. 4500 Fifth Avenue
  31. Pittsburgh, PA 15213
  32. (412) 268-7636
  33. maa@sei.cmu.edu (ARPANET)
  34.  
  35.  
  36. #! /bin/sh
  37. # This is a shell archive, meaning:
  38. # 1. Remove everything above the #! /bin/sh line.
  39. # 2. Save the resulting text in a file.
  40. # 3. Execute the file with /bin/sh (not csh) to create:
  41. #    tst-display.el
  42. #    tst-equal.el
  43. #    tst-inequal.el
  44. #    tst-instrument.el
  45. # This archive created: Thu Aug  6 17:02:17 1987
  46. export PATH; PATH=/bin:/usr/bin:$PATH
  47. echo shar: "extracting 'tst-display.el'" '(12443 characters)'
  48. if test -f 'tst-display.el'
  49. then
  50.     echo shar: "will not over-write existing file 'tst-display.el'"
  51. else
  52. sed 's/^X//' << \SHAR_EOF > 'tst-display.el'
  53. X;;; display.el - GnuTest Display Package
  54. X;;; Copyright (c) 1987 Wang Institute of Graduate Studies
  55. X;;; Andy Bliven <bliven@wanginst>
  56. X
  57. X(provide 'tst-display)
  58. X(require 'tst-annotate)
  59. X
  60. X;;; ----------------------------------------------------------------------
  61. X;;; Public Variables--
  62. X  
  63. X(defconst tst-display-window-width 10
  64. X  "*  Width of each display window, in columns")
  65. X  
  66. X(defconst tst-display-attributes (list 'zero 'constant)
  67. X  "*  List of attributes to be displayed in batch mode.")
  68. X
  69. X;;; ----------------------------------------------------------------------
  70. X;;; Private Variables--
  71. X  
  72. X(defvar tst-display-buffer-alist nil
  73. X  "An alist of attribute names and buffer objects")
  74. X  
  75. X(defvar tst-display-lisp-buffer nil
  76. X  "The buffer of emacs lisp code that has been annotated.")
  77. X  
  78. X(defvar tst-display-lisp-window nil
  79. X  "The window containing emacs lisp code.")
  80. X  
  81. X(defvar tst-display-mode-map nil
  82. X  "Keymap for GnuTest Display major mode.")
  83. X(or tst-display-mode-map
  84. X    (progn
  85. X      (setq tst-display-mode-map (make-keymap))
  86. X      (suppress-keymap tst-display-mode-map) ; requires full keymap, not sparse
  87. X                    ; key definitions
  88. X      (define-key tst-display-mode-map "\C-n"    'tst-display-next-line)
  89. X      (define-key tst-display-mode-map "\C-p"    'tst-display-previous-line)
  90. X      (define-key tst-display-mode-map "\C-v"    'tst-display-scroll-up)
  91. X      (define-key tst-display-mode-map "\M-v"     'tst-display-scroll-down)
  92. X      (define-key tst-display-mode-map "\C-c\C-h" 'tst-display-mode-help)
  93. X      (define-key tst-display-mode-map "\C-cc"   'tst-display-constant)
  94. X      (define-key tst-display-mode-map "\C-cl"   'tst-display-redraw)
  95. X      (define-key tst-display-mode-map "\C-cn"   'tst-display-next)
  96. X      (define-key tst-display-mode-map "\C-cp"   'tst-display-previous)
  97. X      (define-key tst-display-mode-map "\C-cq"   'tst-display-mode-exit)
  98. X      (define-key tst-display-mode-map "\C-cz"   'tst-display-zero)
  99. X      )
  100. X    )
  101. X  
  102. X(defvar tst-display-window-alist nil
  103. X  "An alist of attribute names and window objects")
  104. X
  105. X(defvar tst-batch-results "tst-batch-results"
  106. X  "* a kluge")
  107. X
  108. X(defvar tst-display-saved-variables nil
  109. X  "The property list of this variable contains values of all variables
  110. X   saved on entry to tst-display-mode.")
  111. X  
  112. X
  113. X
  114. X;;; ----------------------------------------------------------------------
  115. X;;; Public Functions--
  116. X  
  117. X(defun tst-display-batch (&optional lisp-buffer)
  118. X  "   Batch mode execution of the annotation display package.  Writes the
  119. X   summary reports 'zero' and 'constant' generated by the tst-analyze
  120. X   package into a 'compilation' style buffer named '*compilation*'.  If
  121. X   called interactively this is available for viewing with the '^X`' key,
  122. X   otherwise it is saved to the file named in tst-batch-results.  If
  123. X   LISP-BUFFER is not specified, current-buffer is used instead as the
  124. X   label on each line of the report."
  125. X  (interactive)
  126. X                    ; body
  127. X  (let ((lisp-buffer (or lisp-buffer (current-buffer)))
  128. X    (save-window (selected-window)))
  129. X    (pop-to-buffer "*compilation*")
  130. X    (erase-buffer)
  131. X    (insert "# GnuTest analysis of " (buffer-name lisp-buffer) "\n"
  132. X        "#   (lines which were never evaluated during tests or returned\n"
  133. X        "#    the same value every time they were evaluated.)\n")
  134. X    (mapcar '(lambda (line)
  135. X           (insert (tst-display-batch-string lisp-buffer
  136. X                         line
  137. X                         'zero
  138. X                         'constant)))
  139. X        (tst-ann-get-lines))
  140. X    (if (interactive-p)
  141. X    (progn
  142. X      (goto-char (point-min))    ; top of results buffer
  143. X      (switch-to-buffer "*compilation*")
  144. X      (select-window save-window)    ; go back to original window
  145. X      )
  146. X      ;; else
  147. X      (write-file tst-batch-results) ; write buffer to disk
  148. X      )
  149. X    )
  150. X  )
  151. X  
  152. X(defun tst-display-mode ()
  153. X  "*  Major mode for displaying GnuTest annotation with associated
  154. X   emacs-lisp code buffer.  Precondition:  tst-instrument and tst-analyze
  155. X   have already been evaluated for this buffer.
  156. X   C-n     tst-display-next-line        
  157. X   C-p     tst-display-previous-line    
  158. X   C-v     tst-display-scroll-up        
  159. X   M-v     tst-display-scroll-down      
  160. X   C-c C-h tst-display-mode-help
  161. X   C-c c   tst-display-constant
  162. X   C-c l   tst-display-redraw           
  163. X   C-c n   tst-display-next
  164. X   C-c p   tst-display-previous
  165. X   C-c q   tst-display-mode-exit
  166. X   C-c z   tst-display-zero
  167. X  "
  168. X  (interactive)
  169. X                    ; body
  170. X  (if (equal major-mode 'tst-display-mode)
  171. X      (tst-display-mode-exit)
  172. X    (put 'tst-display-saved-variables 'mode-name mode-name)
  173. X    (put 'tst-display-saved-variables 'major-mode major-mode)
  174. X    (put 'tst-display-saved-variables 'local-map (current-local-map))
  175. X    (put 'tst-display-saved-variables 'buffer-read-only buffer-read-only)
  176. X    (put 'tst-display-saved-variables 'truncate-lines truncate-lines)
  177. X    (setq mode-name "Test Display")
  178. X    (setq major-mode 'tst-display-mode)
  179. X    (use-local-map tst-display-mode-map) ; setup keymap
  180. X    (set-buffer-modified-p (buffer-modified-p))    ; Idiom to reset modeline.
  181. X    (setq truncate-lines t)
  182. X    (setq buffer-read-only t)
  183. X    (setq tst-display-lisp-buffer (current-buffer))
  184. X    (setq tst-display-lisp-window (selected-window))
  185. X    )
  186. X  )
  187. X
  188. X(defun tst-display-mode-help ()
  189. X  "Help screen for Test Display Mode."
  190. X  (interactive)
  191. X  (with-output-to-temp-buffer "*Help*"
  192. X    (princ (car (cdr (cdr (symbol-function 'tst-display-mode)))))
  193. X    )
  194. X  )
  195. X  
  196. X(defun tst-display-mode-exit ()
  197. X  "exit Test Display Mode"
  198. X  (interactive)
  199. X                    ; close annotation windows
  200. X  (let ((buflist (mapcar 'cdr tst-display-buffer-alist)))
  201. X    (mapcar '(lambda (buf)
  202. X           (and (get-buffer-window buf)
  203. X            (delete-window (get-buffer-window buf))))
  204. X        buflist)
  205. X    )                    ; let
  206. X                    ; clean up global variables
  207. X  (setq tst-display-buffer-alist nil)
  208. X                    ; restore old state
  209. X  (setq mode-name (get 'tst-display-saved-variables 'mode-name))
  210. X  (setq major-mode (get 'tst-display-saved-variables 'major-mode))
  211. X  (use-local-map (get 'tst-display-saved-variables 'local-map))
  212. X  (set-buffer-modified-p (buffer-modified-p))    ; Idiom to reset modeline.
  213. X  (setq truncate-lines (get 'tst-display-saved-variables 'truncate-lines))
  214. X  (setq buffer-read-only (get 'tst-display-saved-variables 'buffer-read-only))
  215. X  )
  216. X  
  217. X(defun tst-display-constant ()
  218. X  "Display values which never changed during test runs."
  219. X  (interactive)
  220. X                    ;body
  221. X  (tst-display-open-buffer 'constant)
  222. X  (tst-display-open-window 'constant)
  223. X  )
  224. X  
  225. X(defun tst-display-zero ()
  226. X  "Display values which were never evaluated during test runs."
  227. X  (interactive)
  228. X                    ;body
  229. X  (tst-display-open-buffer 'zero)
  230. X  (tst-display-open-window 'zero)
  231. X  )
  232. X  
  233. X(defun tst-display-next-line (&optional lines)
  234. X  "Move point down one line in lisp buffer and any annotation buffers."
  235. X  (interactive "p")
  236. X  (let ((nlines (or lines 1))
  237. X    (savewindow (selected-window))
  238. X    (buflist (mapcar 'cdr tst-display-buffer-alist)))
  239. X    (mapcar '(lambda (buf)
  240. X           (let ((win (get-buffer-window buf)))
  241. X         (if win
  242. X             (progn (select-window win)
  243. X                (next-line nlines)))))
  244. X        (cons tst-display-lisp-buffer buflist)
  245. X        )
  246. X    (select-window savewindow)
  247. X    )
  248. X  )
  249. X
  250. X(defun tst-display-previous-line (&optional lines)
  251. X  "Move point up LINES lines (1 if nil) in lisp buffer and any annotation
  252. X   buffers."
  253. X  (interactive "p")
  254. X  (let ((nlines (- (or lines 1))))
  255. X    (tst-display-next-line nlines)
  256. X    )
  257. X  )
  258. X  
  259. X(defun tst-display-scroll-down (&optional lines)
  260. X  "Scroll down LINES lines in lisp buffer and any annotation buffers."
  261. X  (interactive "P")
  262. X  (let ((nlines (and lines (prefix-numeric-value lines)))
  263. X    (savewindow (selected-window))
  264. X    (buflist (mapcar 'cdr tst-display-buffer-alist)))
  265. X    (mapcar '(lambda (buf)
  266. X           (let ((win (get-buffer-window buf)))
  267. X         (if win
  268. X             (progn (select-window win)
  269. X                (scroll-down nlines)))))
  270. X        (cons tst-display-lisp-buffer buflist)
  271. X        )
  272. X    (select-window savewindow)
  273. X    )
  274. X  )
  275. X
  276. X(defun tst-display-scroll-up (&optional lines)
  277. X  "Scroll up LINES lines in lisp buffer and any annotation buffers."
  278. X  (interactive "P")
  279. X  (let ((nlines (and lines (- (prefix-numeric-value lines))))
  280. X    (savewindow (selected-window))
  281. X    (buflist (mapcar 'cdr tst-display-buffer-alist)))
  282. X    (mapcar '(lambda (buf)
  283. X           (let ((win (get-buffer-window buf)))
  284. X         (if win
  285. X             (progn (select-window win)
  286. X                (scroll-up nlines)))))
  287. X        (cons tst-display-lisp-buffer buflist)
  288. X        )
  289. X    (select-window savewindow)
  290. X    )
  291. X  )
  292. X  
  293. X(defun tst-display-open-buffer (attribute)
  294. X  "Create a buffer named *display-ATTRIBUTE*.  Fill it with values from
  295. X   the annotation database."
  296. X  (interactive "Sattribute name: ")
  297. X  (let ((newbuffer nil)
  298. X    (bufname (concat "*tst-"
  299. X             (prin1-to-string attribute)
  300. X             "*")))
  301. X    (save-excursion
  302. X                    ; get buffer
  303. X      (setq newbuffer (get-buffer-create bufname))
  304. X      (setq tst-display-buffer-alist
  305. X        (tst-alist-put tst-display-buffer-alist
  306. X               attribute
  307. X               newbuffer))
  308. X                    ; fill buffer
  309. X      (set-buffer newbuffer)
  310. X      (let ((buffer-read-only nil))
  311. X    (setq mode-line-format (prin1-to-string attribute))
  312. X    (erase-buffer)
  313. X    (newline (tst-display-maxline))
  314. X    (mapcar '(lambda (line)
  315. X           (goto-line line)
  316. X           (insert (tst-display-get-string line attribute)))
  317. X        (tst-ann-get-lines))
  318. X                    ; setup keymap
  319. X    (use-local-map tst-display-mode-map)
  320. X    (setq truncate-lines t)
  321. X    )
  322. X      (setq buffer-read-only t)))
  323. X  )
  324. X  
  325. X(defun tst-display-save-buffer (attribute)
  326. X  "Save a buffer given ATTRIBUTE name."
  327. X  (set-buffer (tst-alist-get tst-display-buffer-alist attribute))
  328. X  (set-visited-file-name (buffer-name))
  329. X  (save-buffer)
  330. X  )
  331. X  
  332. X(defun tst-display-open-window (attribute)
  333. X  "Open a window onto an attribute."
  334. X  (interactive "Sattribute name: ")
  335. X                    ; body
  336. X  (let ((saved-line (tst-display-current-line)))
  337. X    (split-window-horizontally tst-display-window-width)
  338. X    (setq tst-display-window-alist
  339. X      (tst-alist-put tst-display-window-alist
  340. X             attribute
  341. X             (selected-window)))
  342. X    (switch-to-buffer (tst-alist-get tst-display-buffer-alist attribute))
  343. X    (other-window 1)
  344. X    (tst-display-redraw)
  345. X;    (goto-line saved-line)
  346. X;    (recenter)
  347. X;    (recenter)
  348. X    )
  349. X  )
  350. X  
  351. X(defun tst-display-close-window (attribute)
  352. X  "Close a window onto an attribute."
  353. X  (interactive "Sattribute name: ")
  354. X  
  355. X  (let ((win (tst-alist-get tst-display-window-alist attribute)))
  356. X    (and win
  357. X    (progn (delete-window win)
  358. X           (tst-alist-rem tst-display-window-alist attribute)))
  359. X    )
  360. X  )
  361. X  
  362. X(defun tst-display-redraw (&optional line)
  363. X  "Redraw all windows after moving to same line in display-windows
  364. X   as in current window."
  365. X  (interactive)
  366. X  (let ((curline (or line (tst-display-current-line)))
  367. X    (savewindow (selected-window))
  368. X    (buflist (mapcar 'cdr tst-display-buffer-alist)))
  369. X    (mapcar '(lambda (buf)
  370. X           (let ((win (get-buffer-window buf)))
  371. X         (select-window win)
  372. X         (goto-line curline)
  373. X         (recenter)))
  374. X        buflist)
  375. X    (select-window savewindow)
  376. X    (goto-line curline)
  377. X    (recenter)
  378. X    )
  379. X  )
  380. X  
  381. X
  382. X;;; ----------------------------------------------------------------------
  383. X;;; Private Functions--
  384. X
  385. X(defun tst-display-batch-string (buffer line &rest attrlist)
  386. X  "Returns a string 'buffer-name:line-number:values\n'."
  387. X  (let (value string)
  388. X    (setq string (apply 'concat
  389. X            (mapcar '(lambda (attr)
  390. X                   (tst-display-get-string line attr))
  391. X                attrlist))
  392. X      )
  393. X    (if (equal "" string)
  394. X    ""
  395. X      (concat (buffer-name buffer)
  396. X          ":"
  397. X          (prin1-to-string line)
  398. X          "==  "
  399. X          string
  400. X          "\n"))
  401. X    )
  402. X  )
  403. X
  404. X(defun tst-display-get-string (line attribute)
  405. X  "   return a string representation of the value <LINE ATTRIBUTE> from
  406. X   the annotation database."
  407. X                    ; body
  408. X  (let ((value (tst-ann-get line attribute)))
  409. X    (cond
  410. X     ((null value) "")
  411. X     ((and (listp value)
  412. X       (= 1 (length value))) (prin1-to-string (car value)))
  413. X     (t (prin1-to-string value))
  414. X     )
  415. X    )
  416. X  )
  417. X  
  418. X(defun tst-display-maxline ()
  419. X  "Returns number of lines in lisp-buffer"
  420. X  (save-excursion
  421. X   (set-buffer tst-display-lisp-buffer)
  422. X   (count-lines (point-min) (point-max))
  423. X   )
  424. X  )
  425. X  
  426. X(defun tst-display-current-line ()
  427. X  "Returns current line number"
  428. X  (1+ (count-lines (point-min) (point)))
  429. X  )
  430. X  
  431. X(defun tst-display-test-init ()
  432. X  "Test driver for package functions."
  433. X  (interactive)
  434. X  
  435. X  (let ((attr-list tst-display-attributes)
  436. X    (line-list nil)
  437. X    (line 1)
  438. X    )
  439. X                    ; Create a database (cheap)
  440. X    (tst-ann-set-db nil)
  441. X    (goto-char (point-min))
  442. X    (while (not (eobp))
  443. X      (tst-ann-put line 'constant (list line line line))
  444. X      (tst-ann-put line 'zero 'NEVER->>)
  445. X      (next-line 1)
  446. X      (setq line (1+ line))
  447. X      )
  448. X    )
  449. X  )
  450. SHAR_EOF
  451. if test 12443 -ne "`wc -c < 'tst-display.el'`"
  452. then
  453.     echo shar: "error transmitting 'tst-display.el'" '(should have been 12443 characters)'
  454. fi
  455. fi
  456. echo shar: "extracting 'tst-equal.el'" '(32129 characters)'
  457. if test -f 'tst-equal.el'
  458. then
  459.     echo shar: "will not over-write existing file 'tst-equal.el'"
  460. else
  461. sed 's/^X//' << \SHAR_EOF > 'tst-equal.el'
  462. X;;; tst-equal.el -- A number of definitions of equality
  463. X;;; Lorri Menard, Wang Institute of Graduate Studies
  464. X;;; Don Zaremba, Wang Institute of Graduate Studies
  465. X;;; Copyright 1987 Wang Institute of Graduate Studies
  466. X;;;
  467. X
  468. X(provide 'tst-equal)
  469. X
  470. X(defvar tst-equ-log-all-compares "t"
  471. X  "* If not nil then all comparisons are logged into the buffer
  472. X     *equal-log*."
  473. X)
  474. X
  475. X(defvar tst-equ-max-line-diffs "15"
  476. X  "* Maximum number of different lines to log when comparing
  477. X     buffer contents line-by-line. "
  478. X)
  479. X
  480. X(defvar tst-equ-state-functions '(tst-equ-session
  481. X                      tst-equ-buffers 
  482. X                      tst-equ-processes
  483. X                      tst-equ-windows)
  484. X  "* A list of functions to be executed when comparing objects
  485. X     of type state."
  486. X)
  487. X
  488. X(defvar tst-equ-buff-state-functions '(tst-equ-point 
  489. X                  tst-equ-mark
  490. X                  tst-equ-contents
  491. X                  tst-equ-modified
  492. X                  tst-equ-file 
  493. X                  tst-equ-local-vars)
  494. X  "* A list of functions to be executed when comparing objects
  495. X     of type buffer-state."
  496. X)
  497. X
  498. X(defconst tst-equ-indent 3)
  499. X
  500. X(defmacro tst-equ-level1 ()
  501. X (insert "*") (indent-to tst-equ-indent))
  502. X
  503. X(defmacro tst-equ-level2 ()
  504. X  (insert "**") (indent-to (* tst-equ-indent 2)))
  505. X
  506. X(defmacro tst-equ-level3 ()
  507. X  (insert "***") (indent-to (* tst-equ-indent 3)))
  508. X
  509. X(defmacro tst-equ-level4 ()
  510. X  (insert "****") (indent-to (* tst-equ-indent 4)))
  511. X
  512. X(defmacro tst-equ-level5 ()
  513. X  (insert "*****") (indent-to (* tst-equ-indent 5)))
  514. X
  515. X(defmacro tst-equ-level6 ()
  516. X  (insert "******") (indent-to (* tst-equ-indent 6)))
  517. X
  518. X(defmacro tst-equ-level7 ()
  519. X  (insert "*******")  (indent-to (* tst-equ-indent 7)))
  520. X
  521. X(defmacro tst-equ-level8 ()
  522. X  (insert "********")  (indent-to (* tst-equ-indent 8)))
  523. X
  524. X(defmacro tst-equ-level9 ()
  525. X  (insert "*********")  (indent-to (* tst-equ-indent 9)))
  526. X
  527. X
  528. X;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  529. X;   A number of equality testing functions follow. Each is of the
  530. X;   form tst-equ-state-component (state1 state2). Each compares a particular
  531. X;   component from the two states and returns t if equal, else nil.
  532. X;   As a side effect the buffer *equal-log* is updated with the results
  533. X;   of the comparison
  534. X;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  535. X
  536. X;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  537. X
  538. X(defun tst-equ-state (tst-equ-state1 tst-equ-state2 name)
  539. X  "Compares for equality the complete state of a pair of sessions.
  540. X   The two parameters STATE1 and STATE2 must be complete states
  541. X   as returned by tst-reg-capture-state. The results of the comparison
  542. X   are written into buffer *equal-log*. NAME is used to identify the test.
  543. X   Four major components are compared: session, buffers, windows, and
  544. X   processes. "
  545. X
  546. X  (interactive "XState variable 1:
  547. XXState variable 2:
  548. XsName of this test:")
  549. X
  550. X
  551. X  (let (ss-fun-vector function-name tst-equ-result tst-equ-startpoint temppoint)
  552. X
  553. X    (message "Comparing states...")
  554. X    (setq ss-fun-vector tst-equ-state-functions)
  555. X    (setq tst-equ-result t); let's be optomistic
  556. X
  557. X    ; set up the log buffer
  558. X    (get-buffer-create "*equal-log*")
  559. X    (set-buffer "*equal-log*")
  560. X    (outline-mode)
  561. X    (tst-equ-level1)
  562. X    (setq tst-equ-startpoint (point))    ;save "here"
  563. X    (insert "State comparison: " name)
  564. X    (newline)
  565. X    (newline)
  566. X
  567. X    (while ss-fun-vector
  568. X      (progn
  569. X    (setq function-name (car ss-fun-vector))
  570. X    (setq ss-fun-vector (cdr ss-fun-vector))
  571. X    (newline)
  572. X;;;    (insert "  " (prin1-to-string function-name))
  573. X    (newline)
  574. X    (if (not (funcall function-name tst-equ-state1 tst-equ-state2))
  575. X        (setq tst-equ-result nil); set return value if failed
  576. X      ); fi
  577. X    ); ngrop
  578. X      ); elihw
  579. X
  580. X    ; if we failed and a hook exist then run iot
  581. X    (if (and (not tst-equ-result) 'tst-equ-state-hook)
  582. X           (run-hooks 'tst-equ-state-hook))
  583. X
  584. X    (if (not tst-equ-result)
  585. X        (progn
  586. X          (setq temppoint (point))
  587. X          (goto-char tst-equ-startpoint)
  588. X          (insert "?")
  589. X          (goto-char (1+ temppoint))
  590. X          ); ngorp
  591. X      );fi
  592. X    (message "Comparing states... done")
  593. X    tst-equ-result
  594. X    ); tel
  595. X); nufed tst-equ-state
  596. X
  597. X(defun tst-equ-session (state1 state2)
  598. X   "Compares the session components from two states. The
  599. X   two parameters STATE1 and STATE2 must be complete states
  600. X   as returned by tst-reg-capture-state. The session components
  601. X   include: global-bound-syms. "
  602. X
  603. X   (interactive "P")
  604. X
  605. X   (let (sess1 sess2 syms1 syms2 ss-startpoint ss-gs-startpoint temppoint el1 el2)
  606. X    (message "Comparing state of sessions...")
  607. X
  608. X    (goto-char (point-max))        ; .. of output buffer
  609. X    (tst-equ-level2)
  610. X    (setq ss-startpoint (point))
  611. X    (insert "Sessions state")
  612. X    (newline)
  613. X
  614. X    (setq sess1 (cadr (assoc 'session state1)))
  615. X    (setq sess2 (cadr (assoc 'session state2)))
  616. X    
  617. X    (tst-equ-level3)
  618. X    (setq ss-gs-startpoint (point))
  619. X    (insert "Global symbols")
  620. X    (newline)
  621. X
  622. X    (setq syms1 (cadr (assoc 'global-bound-syms sess1)))
  623. X    (setq syms2 (cadr (assoc 'global-bound-syms sess2)))
  624. X    (if (not (setq tst-equ-result (equal syms1 syms2)))
  625. X        (progn
  626. X          (while (and syms1 syms2)
  627. X            (setq el1 (car syms1))
  628. X            (setq syms1 (cdr syms1))
  629. X            (setq el2 (assoc (car el1) syms2))
  630. X            ;;        (debug "nil" el1 el2)
  631. X            (if el2
  632. X                (setq syms2 (delq el2 syms2))
  633. X;;                (list 'setq syms2 (list 'delq (list 'assoc (car el1) syms2) 
  634. X;;                                        syms2))
  635. X              (progn                        ;else ..
  636. X                (indent-to (* tst-equ-indent 4))
  637. X                (insert "?")
  638. X                (insert (prin1-to-string (car el1)) " not found in second state")
  639. X                (newline)
  640. X                ); ngorp
  641. X              ); fi
  642. X            (tst-equ-diff-element el1 el2)
  643. X            ); wlihw
  644. X          (if syms1
  645. X              (progn
  646. X                (while syms1
  647. X                  (setq el1 (car syms1))
  648. X                  (setq syms1 (cdr syms1))
  649. X                  (indent-to (* tst-equ-indent 4))
  650. X                  (insert "?")
  651. X                  (insert (prin1-to-string (car el1)) " not found in second state")
  652. X                  (newline)
  653. X                  ); elihw
  654. X                ); ngorp
  655. X            ); fi
  656. X          (if syms2
  657. X              (progn
  658. X                (while syms2
  659. X                  (setq el2 (car syms2))
  660. X                  (setq syms2 (cdr syms2))
  661. X                  (indent-to (* tst-equ-indent 4))
  662. X                  (insert "?")
  663. X                  (insert (prin1-to-string (car el2)) " not found in first state")
  664. X                  (newline)
  665. X                  ); elihw
  666. X                
  667. X                );ngorp
  668. X            ); fi
  669. X                ); ngorp
  670. X            ; else .. nevermind.
  671. X            ); fi
  672. X    (if (not tst-equ-result)
  673. X        (progn
  674. X          (setq temppoint (point))
  675. X          (goto-char ss-startpoint)
  676. X          (insert "?")
  677. X; if ever there are more things in a session, these two lines need to
  678. X;   be separate.
  679. X          (goto-char ss-gs-startpoint)
  680. X          (insert "?")
  681. X;
  682. X          (goto-char (1+ temppoint))
  683. X          );
  684. X      ); fi
  685. X
  686. X     tst-equ-result
  687. X     ); tel
  688. X)
  689. X;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  690. X
  691. X(defun tst-equ-buffers (tst-equ-buffers1 tst-equ-buffers2)
  692. X  "Compares the buffers components from two states. The
  693. X   two parameters STATE1 and STATE2 must be complete states
  694. X   as returned by tst-reg-capture-state. Compares each buffer for
  695. X   equality with its corresponding buffer (by name) in the other
  696. X   state. tst-equ-buffer-state is called for each pair of buffers. "
  697. X
  698. X  (interactive "P")
  699. X                    ; Local Variables
  700. X  (let (buffers1 buffers2 buff1 buff-name buff2 tst-equ-result buf1names 
  701. X                  bs-startpoint temppoint)  
  702. X
  703. X    (message "Comparing state of buffers...")
  704. X    (setq tst-equ-result t)
  705. X    (setq buffers1 (cadr (assoc 'buffers tst-equ-buffers1))); get the first value
  706. X    (setq buffers2 (cadr (assoc 'buffers tst-equ-buffers2))); get the second value
  707. X
  708. X    ; set up the log buffer
  709. X    (goto-char (point-max))
  710. X    (tst-equ-level2)
  711. X    (setq bs-startpoint (point))
  712. X    (insert "Buffers state")
  713. X    (newline)
  714. X
  715. X    (while buffers1
  716. X      (progn
  717. X        (setq buff1 (car buffers1))
  718. X        (setq buffers1 (cdr buffers1))
  719. X    ; get the name of the 1st buffer and use it to find the second
  720. X        (setq buff-name (cadr (assoc 'buf-state-name buff1)))
  721. X        (setq buf1names (cons buff-name buf1names))
  722. X    
  723. X    ; create a log entry for this buffer
  724. X
  725. X    ; now locate the second buffer
  726. X    (setq buff2 (tst-equ-find-buffer-with-name tst-equ-buffers2 buff-name))
  727. X    (if (not buff2)
  728. X        (progn
  729. X          (newline)
  730. X          (indent-to (* tst-equ-indent 2))
  731. X          (insert "?")
  732. X          (insert buff-name " not found in second state")
  733. X          (newline)
  734. X          (setq tst-equ-result nil)
  735. X          ); ngorp
  736. X      ; else
  737. X        (progn
  738. X          ; now compare them and set tst-equ-result
  739. X          (if (not (tst-equ-buffer-state buff1 buff2))
  740. X                (setq tst-equ-result nil)
  741. X          ) ; fi 
  742. X          ) ; ngorp
  743. X        ); fi
  744. X
  745. X    ); ngrop
  746. X      ); elihw
  747. X;;; now that we have checked for everything from the first state,
  748. X;;;  want to see if there are any buffers in the second state that are
  749. X;;; not in the first one.   Remember the list "buf1names" that was built
  750. X;;; during the first while loop?  Well, we'll member this list instead
  751. X;;; of "tst-equ-find-buffer-with-name"ing it, because this seems more efficient.
  752. X
  753. X    (while buffers2
  754. X      (progn
  755. X        (setq buff2 (car buffers2))
  756. X        (setq buffers2 (cdr buffers2))
  757. X
  758. X        (setq buff-name (cadr (assoc 'buf-state-name buff2)))
  759. X        (if (not (member buff-name buf1names))
  760. X            (progn
  761. X              (newline)
  762. X              (indent-to (* tst-equ-indent 4))
  763. X              (insert "?")
  764. X              (insert buff-name " not found in first state")
  765. X              (newline)
  766. X              (setq tst-equ-result nil)
  767. X              ); ngorp
  768. X          ); fi
  769. X        ); ngorp
  770. X      ); elihw
  771. X              
  772. X    ; if we failed and a hook exist then run it
  773. X    (if (and (not tst-equ-result) 'tst-equ-buffers-hook)
  774. X           (run-hooks 'tst-equ-buffers-hook))
  775. X
  776. X    (if (not tst-equ-result)
  777. X        (progn
  778. X          (setq temppoint (point))
  779. X          (goto-char bs-startpoint)
  780. X          (insert "?")
  781. X          (goto-char (1+ temppoint))
  782. X          ); nprog
  783. X      ); fi
  784. X
  785. X    tst-equ-result
  786. X  ) ; let
  787. X) ; defun tst-equ-buffers
  788. X
  789. X;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  790. X
  791. X(defun tst-equ-windows (tst-equ-windows1 tst-equ-windows2)
  792. X   "Compares the window components from two states. The
  793. X   two parameters STATE1 and STATE2 must be complete states
  794. X   as returned by tst-reg-capture-state."
  795. X
  796. X  (interactive "P")
  797. X                    ; Local Variables
  798. X  (let (window1 window2 tst-equ-result start-point saved-point) 
  799. X
  800. X    (message "Comparing state of windows ...")
  801. X
  802. X    (setq window1 (cadr (assoc 'windows tst-equ-windows1)))
  803. X    (setq window2 (cadr (assoc 'windows tst-equ-windows2)))
  804. X    (setq tst-equ-result t)
  805. X
  806. X    (tst-equ-level2)
  807. X    (setq start-point (point))
  808. X    (insert "Window state")
  809. X    (newline)
  810. X
  811. X    (setq tst-equ-result (tst-equ-wstates window1 window2 ))
  812. X
  813. X    ; if we failed and a hook exist then run iot
  814. X    (if (and (not tst-equ-result) 'tst-equ-windows-hook)
  815. X           (run-hooks 'tst-equ-windows-hook))
  816. X
  817. X    ; if we still fail the out a ?
  818. X    (if (not tst-equ-result)
  819. X    (progn
  820. X      (setq saved-point (point))
  821. X      (goto-char start-point)
  822. X      (insert "?")
  823. X      (goto-char (1+ saved-point))
  824. X      ); ngorp
  825. X      ); if
  826. X
  827. X   tst-equ-result
  828. X    ) ; let
  829. X); defun
  830. X
  831. X(defun tst-equ-wstates (wstate1 wstate2)
  832. X "Check the equality of two windows"
  833. X (let (sibling leftc-edges start-point tst-equ-result tresult obj1 obj2 assoc-list
  834. X           label-list component label childs1 childs2 cl1 cl2 cr1 cr2)
  835. X
  836. X   (setq tst-equ-result t)
  837. X
  838. X   ; check for spilt windows 
  839. X   (if (assoc 'split wstate1)
  840. X       (progn
  841. X     (setq childs1 (cadr (assoc 'children wstate1)))
  842. X     (setq childs2 (cadr (assoc 'children wstate2)))
  843. X     ; Save the children
  844. X     (setq cl1 (car childs1))
  845. X     (setq cl2 (car childs2))
  846. X     (setq cr1 (car (cdr childs1)))
  847. X     (setq cr2 (car (cdr childs2)))
  848. X
  849. X     ; Now do the comparisons
  850. X     (setq tresult (tst-equ-wstates cl1 cl2))
  851. X     (setq tst-equ-result (and tresult (tst-equ-wstates cr1 cr2)))
  852. X     ); progn
  853. X     ); if split
  854. X
  855. X   ; else not spilt so compare windows
  856. X    (progn
  857. X      ; first set up the assoc and label list
  858. X      (setq assoc-list '(window-edges window-buffer window-start window-point
  859. X                   current-window))
  860. X      (setq label-list '(edges buffer start point current))
  861. X
  862. X      ; setup *equal-log* buffer
  863. X      (newline)
  864. X      (tst-equ-level3)
  865. X      (setq start-point (point))
  866. X      (insert "window")
  867. X      (newline)
  868. X
  869. X      ; loop thru the full assoc list
  870. X      (while assoc-list
  871. X    (progn
  872. X      (setq component (car assoc-list))
  873. X      (setq assoc-list (cdr assoc-list))
  874. X      (setq label (car label-list))
  875. X      (setq label-list (cdr label-list))
  876. X
  877. X      ; now get the two objects and compare them
  878. X      (tst-equ-level4)
  879. X      (setq obj1 (cadr (assoc component wstate1)))
  880. X      (setq obj2 (cadr (assoc component wstate2)))
  881. X      (setq tresult (equal obj1 obj2))
  882. X      (if (not tresult)
  883. X          (progn
  884. X        (insert "?")
  885. X        (setq tst-equ-result nil)
  886. X        ); ngorp
  887. X        ; else
  888. X        (insert " ")
  889. X        ); if
  890. X      (insert (prin1-to-string component) ": ")
  891. X      (tst-equ-log-diff tresult obj1 obj2)
  892. X      ); progn after the while
  893. X    ); while assoc-list
  894. X
  895. X      tst-equ-result
  896. X      ); progn
  897. X   ); let
  898. X); defun
  899. X
  900. X;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  901. X
  902. X(defun tst-equ-processes (state1 state2)
  903. X   "Compares the process components from two states. The
  904. X   two parameters STATE1 and STATE2 must be complete states
  905. X   as returned by tst-reg-capture-state. The session components
  906. X   include: command exit-status filter name sentinel status. "
  907. X
  908. X  (interactive "P")
  909. X                    ; Local Variables
  910. X  (let (proc1 proc2 p1 p2 c1 c2 tst-equ-result proc-list component start-point
  911. X          saved-point) 
  912. X
  913. X    (message "Comparing state of processes...")
  914. X    (setq proc-list '(command exit-status filter name sentinel status))
  915. X
  916. X    (setq proc1 (cadr (assoc 'processes state1)))
  917. X    (setq proc2 (cadr (assoc 'processes state2)))
  918. X    (setq tst-equ-result t)
  919. X
  920. X    (tst-equ-level2)
  921. X    (setq start-point (point))
  922. X    (insert "Processes state")
  923. X    (newline)
  924. X
  925. X    (while proc1 
  926. X      (progn
  927. X    (setq p1 (car proc1))
  928. X    (setq proc1 (cdr proc1))
  929. X    (setq p2 (car proc2))
  930. X    (setq proc2 (cdr proc2))
  931. X
  932. X    (setq proc-list '(command exit-status filter name 
  933. X                  sentinel status process-mark))
  934. X    (newline)
  935. X    (while proc-list
  936. X      (progn
  937. X        (setq component (car proc-list))
  938. X        (setq proc-list (cdr proc-list))
  939. X        (setq c1 (cadr (assoc component p1)))
  940. X        (setq c2 (cadr (assoc component p2)))
  941. X        (setq cresult (equal c1 c2))
  942. X
  943. X        (tst-equ-level3)
  944. X        (if (not cresult)
  945. X        (progn
  946. X          (insert "?")
  947. X          (setq tst-equ-result nil)
  948. X          ); ngorp
  949. X          ; else
  950. X             (insert " ")
  951. X          ); fi
  952. X        (insert (prin1-to-string component) ": ")
  953. X        (tst-equ-log-diff cresult c1 c2)
  954. X        ); ngorp
  955. X      ); elihw
  956. X
  957. X
  958. X    ); ngorp
  959. X      ); while proc1
  960. X
  961. X    ; if we failed and a hook exist then run iot
  962. X    (if (and (not tst-equ-result) 'tst-equ-processes-hook)
  963. X           (run-hooks 'tst-equ-processes-hook))
  964. X    (if (not tst-equ-result)
  965. X    (progn
  966. X      (setq saved-point (point))
  967. X      (goto-char start-point)
  968. X      (insert "?")
  969. X      (goto-char (1+ saved-point))
  970. X      ); ngorp
  971. X      ); fi
  972. X    tst-equ-result
  973. X  ); tel
  974. X); nufed
  975. X
  976. X
  977. X(defun tst-equ-buffer-state (buff-state1 buff-state2)
  978. X   "Compares two buffers for equality. The two parameters 
  979. X    BUFFER1 and BUFFER2 must be buffer states as returned
  980. X    by tst-equ-find-buffer. The following components are
  981. X    compared by default: point mark contents file local-variables.
  982. X    This can be modified by changing the elemetns in the variable
  983. X    tst-equ-buff-state-functions. "
  984. X
  985. X  (interactive "P")
  986. X
  987. X; Variables
  988. X
  989. X  (let (bs-fun-vector function-name tst-equ-result saved-beg msg
  990. X              fname
  991. X              saved-end tst-equ-buffer-state-startpoint)
  992. X    (get-buffer-create "*equal-log*")
  993. X    (set-buffer "*equal-log*")
  994. X    (outline-mode)
  995. X    (goto-char (point-max))
  996. X
  997. X    (newline)
  998. X    (tst-equ-level2)
  999. X    (setq tst-equ-buffer-state-startpoint (point))
  1000. X    (insert "Comparison of buffers named: "  )
  1001. X    (insert (cadr (assoc 'buf-state-name buff-state1)))
  1002. X    (newline)
  1003. X
  1004. X    (setq msg (concat "Comparing state of buffer " 
  1005. X              (cadr (assoc 'buf-state-name buff-state1))))
  1006. X    (message msg)
  1007. X
  1008. X  (setq bs-fun-vector tst-equ-buff-state-functions)
  1009. X  (setq tst-equ-result t) ; let's be optomistic
  1010. X
  1011. X  (while bs-fun-vector
  1012. X    (progn
  1013. X      (setq function-name (car bs-fun-vector))
  1014. X      (setq bs-fun-vector (cdr bs-fun-vector))
  1015. X
  1016. X      (tst-equ-level3)
  1017. X      (setq saved-beg (point))
  1018. X      (setq fname (prin1-to-string function-name))
  1019. X      (setq fname (substring fname (match-end 
  1020. X                 (string-match "tst-equ-" fname)) nil))
  1021. X      (insert fname ": ")
  1022. X;      (newline)
  1023. X      (if (not (funcall function-name buff-state1 buff-state2))
  1024. X          (progn
  1025. X            (setq tst-equ-result nil)   ; set return value if failed
  1026. X            (setq saved-end (point))
  1027. X            (goto-char saved-beg)
  1028. X            (insert "?")
  1029. X            (goto-char (1+ saved-end))
  1030. X
  1031. X            ); ngorp
  1032. X        ); fi
  1033. X
  1034. X      ); progn
  1035. X    ); while
  1036. X  (if (not tst-equ-result)
  1037. X      (progn
  1038. X        (setq temppoint (point))
  1039. X        (goto-char tst-equ-buffer-state-startpoint)
  1040. X        (insert "?")
  1041. X        (goto-char (1+ temppoint))
  1042. X        ); ngorp
  1043. X    ); fi
  1044. X       tst-equ-result
  1045. X  ) ; let
  1046. X
  1047. X) ; defun tst-equ-buffer-state
  1048. X
  1049. X
  1050. X;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1051. X
  1052. X(defun tst-equ-contents (buff-state1 buff-state2)
  1053. X  "Compares the contents component from two buffer states. "
  1054. X
  1055. X  (interactive "P")
  1056. X                    ; Local Variables
  1057. X  (let (tst-equ-contents1 tst-equ-contents2 tst-equ-result) 
  1058. X    
  1059. X    (setq tst-equ-contents1 (cadr (assoc 'buf-state-contents buff-state1)))
  1060. X    (setq tst-equ-contents2 (cadr (assoc 'buf-state-contents buff-state2)))
  1061. X    (setq tst-equ-result (string-equal tst-equ-contents1 tst-equ-contents2))
  1062. X
  1063. X    ; if a hook exist and we failed the compare then run the hook ..
  1064. X    (if (and (not tst-equ-result) 'tst-equ-contents-hook)
  1065. X           (run-hooks 'tst-equ-contents-hook))
  1066. X
  1067. X    (if (not tst-equ-result)
  1068. X        (progn
  1069. X          (indent-to (* tst-equ-indent 4))
  1070. X          (insert "contents not equal")
  1071. X          ); ngorp
  1072. X      (progn
  1073. X        (indent-to (* tst-equ-indent 4))
  1074. X        (insert "contents equal")
  1075. X        ); ngorp
  1076. X      ); fi
  1077. X    (newline)
  1078. X    tst-equ-result
  1079. X  ) ; let
  1080. X) ; defun tst-equ-contents
  1081. X
  1082. X;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1083. X
  1084. X(defun tst-equ-contents-region (buff-state1 buff-state2)
  1085. X  "Compares the contents component from two buffer states between
  1086. X   point and mark. "
  1087. X
  1088. X  (interactive "P")
  1089. X                    ; Local Variables
  1090. X  (let (tst-equ-contents-region1 tst-equ-contents-region2 
  1091. X                 buf-point buf-mark tst-equ-result) 
  1092. X    
  1093. X    (setq tst-equ-contents-region1 (cadr (assoc 'buf-state-contents buff-state1)))
  1094. X    (setq buf-point (cadr (assoc 'buf-state-point buff-state1)))
  1095. X    (setq buf-mark  (cadr (assoc 'buf-state-mark buff-state1)))
  1096. X    (setq tst-equ-contents-region1 
  1097. X      (substring tst-equ-contents-region1 buf-point buf-mark))
  1098. X
  1099. X    (setq tst-equ-contents-region2 (cadr (assoc 'buf-state-contents buff-state2)))
  1100. X    (setq buf-point (cadr (assoc 'buf-state-point buff-state2)))
  1101. X    (setq buf-mark  (cadr (assoc 'buf-state-mark buff-state2)))
  1102. X    (setq tst-equ-contents-region2
  1103. X      (substring tst-equ-contents-region2 buf-point buf-mark))
  1104. X
  1105. X    (setq tst-equ-result (string-equal 
  1106. X          tst-equ-contents-region1 tst-equ-contents-region2))
  1107. X
  1108. X    ; if a hook exist and we failed the compare then run the hook ..
  1109. X    (if (and (not tst-equ-result) 'tst-equ-contents-region-hook)
  1110. X           (run-hooks 'tst-equ-contents-region-hook))
  1111. X
  1112. X    (if (not tst-equ-result)
  1113. X        (progn
  1114. X          (indent-to (* tst-equ-indent 4))
  1115. X          (insert "contents not equal")
  1116. X          ); ngorp
  1117. X      (progn
  1118. X        (indent-to (* tst-equ-indent 4))
  1119. X        (insert "contents equal")
  1120. X        ); ngorp
  1121. X      ); fi
  1122. X    (newline)
  1123. X    tst-equ-result
  1124. X  ) ; let
  1125. X) ; defun tst-equ-contents-region
  1126. X
  1127. X;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1128. X
  1129. X(defun tst-equ-contents-line (buff-state1 buff-state2)
  1130. X  "Compares the contents component from two buffer states. Comparison
  1131. X   is performed line by line. Will run a hook named 'tst-equ-line-hook
  1132. X   that can access the strings tst-equ-line1 and tst-equ-line2. Hook is
  1133. X   called only if the comparison fails but can set tst-equ-result to t if
  1134. X   it wants."
  1135. X
  1136. X  (interactive "P")
  1137. X                    ; Local Variables
  1138. X  (let (c1 c2 tst-equ-line1 tst-equ-line2 tst-equ-result more1 more2 
  1139. X       start1 end1 start2 end2 final-result found-so-far) 
  1140. X    
  1141. X    (setq c1 (cadr (assoc 'buf-state-contents buff-state1))); get the first value
  1142. X    (setq c2 (cadr (assoc 'buf-state-contents buff-state2))); get the second value
  1143. X    (setq final-result t more1 t more2 t)
  1144. X    (setq start1 0 start2 0 found-so-far 0); starting index in strings
  1145. X
  1146. X
  1147. X    (while (and more1 more2)
  1148. X      (progn
  1149. X    (setq end1 (string-match "\n" c1 start1))
  1150. X    (if (not end1)
  1151. X        (setq more1 nil); we hit end-of-contents
  1152. X    ; else
  1153. X      (progn
  1154. X        (setq tst-equ-line1 (substring c1 start1 end1 ))
  1155. X        (setq start1 (match-end 0))
  1156. X        ); ngorp
  1157. X      ); fi
  1158. X    (setq end2 (string-match "\n" c2 start2))
  1159. X    (if (not end2)
  1160. X        (setq more2 nil); we hit end-of-contents
  1161. X    ; else
  1162. X      (progn
  1163. X        (setq tst-equ-line2 (substring c2 start2 end2 ))
  1164. X        (setq start2 (match-end 0))
  1165. X        ); ngorp
  1166. X      ); fi
  1167. X
  1168. X    ; now do the comparison if we have two lines
  1169. X    (if (and more1 more2)
  1170. X      (progn
  1171. X        (setq tst-equ-result (string-equal tst-equ-line1 tst-equ-line2))
  1172. X
  1173. X        ; if a hook exist and we failed the compare then run the hook ..
  1174. X        (if (and (not tst-equ-result) 'tst-equ-line-hook)
  1175. X          (run-hooks 'tst-equ-line-hook))
  1176. X
  1177. X        ; but test again in case hook modified result
  1178. X        (if (not tst-equ-result)
  1179. X        (progn
  1180. X          (setq final-result nil)
  1181. X          (tst-equ-log-diff-line tst-equ-line1 tst-equ-line2)
  1182. X          (setq found-so-far (+ 1 found-so-far))
  1183. X          (if (>=  found-so-far tst-equ-max-line-diffs)
  1184. X              (progn
  1185. X                ; i want to just get out of here.
  1186. X                (setq more1 nil)
  1187. X                (setq more2 nil)        ;fake 'em into leaving
  1188. X                ); ngorp
  1189. X            ); fi
  1190. X          ); ngorp
  1191. X         ); fi
  1192. X       ); ngorp
  1193. X     ); fi
  1194. X    ); ngorp
  1195. X      ); elihw
  1196. X    final-result
  1197. X  ) ; let
  1198. X) ; defun tst-equ-contents-line
  1199. X
  1200. X;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1201. X
  1202. X(defun tst-equ-point (buff-state1 buff-state2)
  1203. X  "Compares the point component from two buffer states. "
  1204. X
  1205. X  (interactive "P")
  1206. X                    ; Local Variables
  1207. X  (let (tst-equ-point1 tst-equ-point2 tst-equ-result) 
  1208. X    
  1209. X    (setq tst-equ-point1 (cadr (assoc 'buf-state-point buff-state1)))
  1210. X    (setq tst-equ-point2 (cadr (assoc 'buf-state-point buff-state2)))
  1211. X    (setq tst-equ-result (equal tst-equ-point1 tst-equ-point2))
  1212. X
  1213. X    ; if a hook exist and we failed the compare then run the hook ..
  1214. X    (if (and (not tst-equ-result) 'tst-equ-point-hook)
  1215. X           (run-hooks 'tst-equ-point-hook))
  1216. X    
  1217. X    (tst-equ-log-diff tst-equ-result (int-to-string tst-equ-point1) 
  1218. X              (int-to-string tst-equ-point2))
  1219. X    tst-equ-result
  1220. X  ) ; let
  1221. X) ; defun tst-equ-point
  1222. X
  1223. X;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1224. X
  1225. X(defun tst-equ-mark (buff-state1 buff-state2)
  1226. X  "Compares the mark component from two buffer states. "
  1227. X
  1228. X  (interactive "P")
  1229. X                    ; Local Variables
  1230. X  (let (tst-equ-mark1 tst-equ-mark2 tst-equ-result) 
  1231. X    
  1232. X    (setq tst-equ-mark1 (cadr (assoc 'buf-state-mark buff-state1)))
  1233. X    (setq tst-equ-mark2 (cadr (assoc 'buf-state-mark buff-state2)))
  1234. X    (setq tst-equ-result (equal tst-equ-mark1 tst-equ-mark2))
  1235. X
  1236. X    ; if a hook exist and we failed the compare then run the hook ..
  1237. X    (if (and (not tst-equ-result) 'tst-equ-mark-hook)
  1238. X           (run-hooks 'tst-equ-mark-hook))
  1239. X
  1240. X    (tst-equ-log-diff tst-equ-result  tst-equ-mark1 tst-equ-mark2)
  1241. X    tst-equ-result
  1242. X
  1243. X  ) ; let
  1244. X) ; defun tst-equ-mark
  1245. X
  1246. X;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1247. X
  1248. X(defun tst-equ-modified (buff-state1 buff-state2)
  1249. X  "Compares the modified component from two buffer states. "
  1250. X
  1251. X  (interactive "P")
  1252. X                    ; Local Variables
  1253. X  (let (tst-equ-modified1 tst-equ-modified2 tst-equ-result) 
  1254. X    
  1255. X    (setq tst-equ-modified1 (cadr (assoc 'buf-state-modified buff-state1)))
  1256. X    (setq tst-equ-modified2 (cadr (assoc 'buf-state-modified buff-state2)))
  1257. X    (setq tst-equ-result (equal tst-equ-modified1 tst-equ-modified2))
  1258. X
  1259. X    ; if a hook exist and we failed the compare then run the hook ..
  1260. X    (if (and (not tst-equ-result) 'tst-equ-modified-hook)
  1261. X           (run-hooks 'tst-equ-modified-hook))
  1262. X
  1263. X    (tst-equ-log-diff tst-equ-result  tst-equ-modified1 tst-equ-modified2)
  1264. X    tst-equ-result
  1265. X
  1266. X  ) ; let
  1267. X) ; defun tst-equ-modified
  1268. X
  1269. X;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1270. X
  1271. X(defun tst-equ-file (buff-state1 buff-state2)
  1272. X  "Compares the file component from two buffer states. "
  1273. X
  1274. X  (interactive "P")
  1275. X                    ; Local Variables
  1276. X  (let (tst-equ-file1 tst-equ-file2 tst-equ-result) 
  1277. X    
  1278. X    (setq tst-equ-file1 (cadr (assoc 'buf-state-file buff-state1))); get the first value
  1279. X    (setq tst-equ-file2 (cadr (assoc 'buf-state-file buff-state2))); get the second value
  1280. X    (setq tst-equ-result (equal tst-equ-file1 tst-equ-file2))
  1281. X
  1282. X    ; if a hook exist and we failed the compare then run the hook ..
  1283. X    (if (and (not tst-equ-result) 'tst-equ-file-hook)
  1284. X           (run-hooks 'tst-equ-file-hook))
  1285. X
  1286. X    (tst-equ-log-diff tst-equ-result  tst-equ-file1 tst-equ-file2)
  1287. X    tst-equ-result
  1288. X
  1289. X  ) ; let
  1290. X) ; defun tst-equ-file
  1291. X
  1292. X
  1293. X;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1294. X(defun tst-equ-diff-element (el1 el2)
  1295. X  " Logs differences between the two elements based on the type of 
  1296. Xelement that it is. (keymap, vector, string, list)"
  1297. X
  1298. X  (let ()
  1299. X
  1300. X    (cond  ((keymapp (cdr el1)) (tst-equ-log-keymap el1 el2))
  1301. X           ((syntax-table-p (cdr el1)) (tst-equ-log-syntable el1 el2))
  1302. X           ((stringp (cdr el1)) (tst-equ-log-string el1 el2))
  1303. X           ((atom (cdr el1)) (tst-equ-log-atom el1 el2))
  1304. X           ((arrayp (cdr el1)) (tst-equ-log-array el1 el2))
  1305. X           (t (tst-equ-log-fubar el1 el2))
  1306. X           ); dnoc
  1307. X); tel
  1308. X); defun tst-equ-diff-element
  1309. X
  1310. X(defun tst-equ-log-fubar (el1 el2)
  1311. X" Generic equal-comparer for elements of a symbol"
  1312. X
  1313. X  (let ()
  1314. X    (if (not (equal el1 el2))
  1315. X      (progn  
  1316. X;        (debug nil "in fubar" el1 el2)
  1317. X        (indent-to (* tst-equ-indent 4))
  1318. X        (insert (prin1-to-string (car el1)))
  1319. X        (if (cdr el1)
  1320. X            (insert ": "(prin1-to-string (cdr el1))  " "
  1321. X                (prin1-to-string (cdr el2)))
  1322. X          ); fi
  1323. X        (newline)
  1324. X        ); ngorp
  1325. X      ); fi
  1326. X); tel
  1327. X); defun tst-equ-log-fubar
  1328. X    
  1329. X(defun tst-equ-log-string (el1 el2)
  1330. X
  1331. X  (let ()
  1332. X
  1333. X    (if (not (equal el1 el2))
  1334. X      (progn  
  1335. X;        (debug nil "In string" (car el1))
  1336. X        (indent-to (* tst-equ-indent 4))
  1337. X        (insert (prin1-to-string (car el1)))
  1338. X        (newline)
  1339. X        ); ngorp
  1340. X      ); fi
  1341. X      ); tel
  1342. X); defun tst-equ-log-string
  1343. X
  1344. X(defun tst-equ-log-atom (el1 el2)
  1345. X
  1346. X  (let ()
  1347. X
  1348. X    (if (not (equal el1 el2))
  1349. X      (progn  
  1350. X;        (debug nil "in atom" el1 el2)
  1351. X        (indent-to (* tst-equ-indent 4))
  1352. X        (insert (prin1-to-string (car el1))
  1353. X                "   " (prin1-to-string (cdr el1))
  1354. X                " " (prin1-to-string (cdr el2)))
  1355. X        (newline)
  1356. X        ); ngorp
  1357. X      ); fi
  1358. X      ); tel
  1359. X); defun tst-equ-log-atom
  1360. X
  1361. X(defun tst-equ-log-syntable (a1 a2)
  1362. X  " Outputs the differences between two syntax tables in the form:
  1363. X      element_number : value1  value2"
  1364. X
  1365. X  (let (e1 e2 index)
  1366. X;    (debug nil "In syntable" (car el1))
  1367. X    (if (not (equal a1 a2))
  1368. X          (while (not (= index 256))
  1369. X            (setq e1 (aref a1 index))
  1370. X            (setq e2 (aref a2 index))
  1371. X            (if (not (equal e1 e2))
  1372. X                (progn
  1373. X                  (indent-to (* tst-equ-indent 4))
  1374. X                  (insert (prin1-to-string index) ": "
  1375. X                    (prin1-to-string e1) " " (prin1-to-string e2))
  1376. X                  (newline)
  1377. X                  );ngorp
  1378. X              ); fi
  1379. X            (+1 index)
  1380. X            ); elihw
  1381. X      ); fi
  1382. X          ); tel
  1383. X); defun tst-equ-log-syntable
  1384. X
  1385. X
  1386. X
  1387. X(defun tst-equ-log-keymap (a1 a2)
  1388. X  " Outputs only the fact that two keymaps do not match.  Has the potential
  1389. X     for future enhancements (like, describing which keys don't match"
  1390. X
  1391. X;  (debug nil "in keymap" (car el1))
  1392. X  (if (not (equal a1 a2))
  1393. X      (progn
  1394. X        (indent-to (* tst-equ-indent 4))
  1395. X        (insert (prin1-to-string (car a1)))
  1396. X        ); ngorp
  1397. X    );fi
  1398. X); defun tst-equ-log-keymap
  1399. X;  (let (e1 e2 index)
  1400. X;          (while (not (= index 256))
  1401. X;            (setq e1 (aref a1 index))
  1402. X;            (setq e2 (aref a2 index))
  1403. X;            (if (not (equal e1 e2))
  1404. X;                (progn
  1405. X;                  (indent-to (* tst-equ-indent 4))
  1406. X;                  (insert (prin1-to-string index) ": "
  1407. X;                    (prin1-to-string e1) " " (prin1-to-string e2))
  1408. X;                  (newline)
  1409. X;                  );ngorp
  1410. X;              ); fi
  1411. X;            (+1 index)
  1412. X;            ); elihw
  1413. X;
  1414. X;          ); tel
  1415. X;); defun tst-equ-log-syntable
  1416. X
  1417. X
  1418. X
  1419. X(defun tst-equ-log-diff (equal-flag  v1 v2)
  1420. X  "Logs differences in *equal-log* buffer. "
  1421. X
  1422. X
  1423. X  (let ()
  1424. X      (if (or tst-equ-log-all-compares (not equal-flag))
  1425. X          (progn
  1426. X            (indent-to (* tst-equ-indent 4))
  1427. X            (insert (prin1-to-string v1) " " (prin1-to-string v2))
  1428. X            (newline)
  1429. X            ); ngorp
  1430. X        );fi
  1431. X
  1432. X  ) ; let
  1433. X) ; defun tst-equ-log-diff
  1434. X;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1435. X
  1436. X(defun tst-equ-log-diff-line (line1 line2)
  1437. X  "Logs differences in *equal-log* buffer. "
  1438. X
  1439. X
  1440. X  (let ()
  1441. X
  1442. X      (goto-char (point-max))
  1443. X      (newline)
  1444. X      (indent-to (* tst-equ-indent 4))
  1445. X      (insert "1: " line1)
  1446. X      (newline)
  1447. X      (indent-to (* tst-equ-indent 4))
  1448. X      (insert "2: " line2)
  1449. X      (newline)
  1450. X
  1451. X  ) ; let
  1452. X) ; defun tst-equ-log-diff-line
  1453. X
  1454. X
  1455. X;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1456. X
  1457. X(defun tst-equ-find-buffer-with-name (state name )
  1458. X    "Return a buff-state of the buffer from STATE with name NAME."
  1459. X
  1460. X; Variables
  1461. X
  1462. X  (let  (buffers buff-state buff-name found)
  1463. X
  1464. X    (setq found nil)
  1465. X    (setq buffers (cadr (assoc 'buffers state)))
  1466. X
  1467. X
  1468. X    (while (not found)
  1469. X      (progn
  1470. X    (setq buff-state (car buffers))
  1471. X    (setq buffers (cdr buffers))
  1472. X    (setq buff-name (cadr (assoc 'buf-state-name buff-state)))
  1473. X    (if (equal buff-name name) 
  1474. X        (setq found t)
  1475. X    ; else
  1476. X        (progn 
  1477. X          (if (not buffers) 
  1478. X          (progn 
  1479. X            (setq found t)
  1480. X            (setq buff-state nil)
  1481. X            ); progn
  1482. X         ); fi
  1483. X        ); ngrop
  1484. X      ); if
  1485. X    ); progn
  1486. X      ); while
  1487. X    buff-state
  1488. X  ) ; let
  1489. X) ; defun tst-equ-find-buffer-with-name
  1490. X
  1491. X;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1492. X
  1493. X(defun tst-equ-named-buff-states (state1 name1 state2 name2)
  1494. X  " Compares, from STATE1, the state of the buffer who's name is
  1495. X    NAME1 with, from STATE2,  the state of the buffer who's name
  1496. X    is NAME2. If STATE2 is nil, then a buffer of NAME2 is expected
  1497. X    in STATE1. "
  1498. X
  1499. X  (interactive "P")
  1500. X                       
  1501. X; Variables
  1502. X
  1503. X  (let  (buff-state-1 buff-state-2)
  1504. X
  1505. X    ; first locate the buffers
  1506. X    (setq buff-state-1 (tst-equ-find-buffer-with-name state1 name1))
  1507. X    (if state2
  1508. X    (setq buff-state-2 (tst-equ-find-buffer-with-name state2 name2))
  1509. X    ; else
  1510. X    (setq buff-state-2 (tst-equ-find-buffer-with-name state1 name2))
  1511. X    ) ; if
  1512. X    (tst-equ-buffer-state buff-state-1 buff-state-2)
  1513. X
  1514. X  ) ; let
  1515. X) ; defun tst-equ-named-buff-states
  1516. X
  1517. X(defun tst-equ-local-vars (b1  b2)
  1518. X   " Compares the values of the local variables in two buffers and
  1519. X     logs the ones that are different."
  1520. X
  1521. X     
  1522. X   (interactive "P")
  1523. X
  1524. X   (let (vars1 vars2 var1 var2 tst-equ-result firsttime)
  1525. X
  1526. X    (setq tst-equ-result t)            ;default to "all equal "
  1527. X    (setq firsttime nil)                ;still just my first time ...
  1528. X
  1529. X
  1530. X     (setq vars1 (cadr (assoc 'buf-state-local-vars b1)))
  1531. X
  1532. X     (setq vars2 (cadr (assoc 'buf-state-local-vars b2)))
  1533. X
  1534. X     (while vars1                        ;go through the b1 vars first.
  1535. X       (setq var1 (car vars1))          ;get the next variable
  1536. X       (setq vars1 (cdr vars1))            ;.. and set the list to the tail
  1537. X       (setq var2 (assoc (car var1) vars2)) ; find this variable in b2
  1538. X       (if var2
  1539. X           (progn
  1540. X             (if (not (equal var1 var2))
  1541. X                 (progn
  1542. X                   (if (not firsttime)
  1543. X                       (progn
  1544. X                         (indent-to (* tst-equ-indent 3))
  1545. X                         (insert "local variables not equal ")
  1546. X                         (newline)
  1547. X                         (setq firsttime t)
  1548. X                         ); ngorp
  1549. X                     ); fi
  1550. X                   (setq tst-equ-result nil)
  1551. X                   (indent-to (* tst-equ-indent 4))
  1552. X                   (insert (prin1-to-string (car var1))
  1553. X                    "   " (prin1-to-string (cdr var1))
  1554. X                    " " (prin1-to-string (cdr var2)))
  1555. X                   (newline)
  1556. X                   ); ngorp
  1557. X         );fi
  1558. X       ); ngorp
  1559. X         ; else
  1560. X         (progn
  1561. X           (setq tst-equ-result nil)
  1562. X           (if (not firsttime)
  1563. X               (progn
  1564. X                 (insert "?")
  1565. X                 (indent-to (* tst-equ-level 3))
  1566. X                 (insert "local variables not equal ")
  1567. X                 (newline)
  1568. X                 (setq firsttime t)
  1569. X                 ); ngorp
  1570. X             ); fi
  1571. X           (indent-to (* tst-equ-level 4))
  1572. X           (insert  (prin1-to-string (car var1)) "not found in second buffer ")
  1573. X           (newline)
  1574. X           ); ngorp (of else)
  1575. X         ); fi [if vars2]
  1576. X       ); elihw
  1577. X
  1578. X     (setq vars1 (cadr (assoc 'buf-state-local-vars b1)))
  1579. X     (while vars2
  1580. X       
  1581. X       (setq var2 (car vars2))          ;get the next variable
  1582. X       (setq vars2 (cdr vars2))            ;.. and set the list to the tail
  1583. X       (setq var1 (assoc (car var2) vars1))
  1584. X       (if (not var1)
  1585. X         (progn
  1586. X           (setq tst-equ-result nil)
  1587. X           (if (not firsttime)
  1588. X               (progn
  1589. X                 (indent-to (* tst-equ-indent 4))
  1590. X                 (insert "local variables not equal:")
  1591. X                 (newline)
  1592. X                 (setq firsttime t)
  1593. X                 ); ngorp
  1594. X             ); fi
  1595. X           (indent-to (* tst-equ-indent 4))
  1596. X           (insert (prin1-to-string (car var2)) " not found in first buffer " )
  1597. X           (newline)
  1598. X           ); ngorp (of else)
  1599. X         ); fi 
  1600. X       ); elihw
  1601. X     (if tst-equ-result
  1602. X         (progn
  1603. X           (indent-to (* tst-equ-indent 4))
  1604. X           (insert "local variables are equal ")
  1605. X           (newline)
  1606. X           ); ngorp
  1607. X       ); fi
  1608. X     tst-equ-result                                ;return the tst-equ-result
  1609. X     ); tel
  1610. X   ); defun tst-equ-local-vars
  1611. X
  1612. X
  1613. X
  1614. SHAR_EOF
  1615. if test 32129 -ne "`wc -c < 'tst-equal.el'`"
  1616. then
  1617.     echo shar: "error transmitting 'tst-equal.el'" '(should have been 32129 characters)'
  1618. fi
  1619. fi
  1620. echo shar: "extracting 'tst-inequal.el'" '(3828 characters)'
  1621. if test -f 'tst-inequal.el'
  1622. then
  1623.     echo shar: "will not over-write existing file 'tst-inequal.el'"
  1624. else
  1625. sed 's/^X//' << \SHAR_EOF > 'tst-inequal.el'
  1626. X;;; inequal.el -- A number of inequality functions. 
  1627. X;;; See also equal.el
  1628. X;;; Lorri Menard, Wang Institute of Graduate Studies
  1629. X;;; Don Zaremba, Wang Institute of Graduate Studies
  1630. X;;; Copyright 1987 Wang Institute of Graduate Studies
  1631. X;;;
  1632. X
  1633. X(provide 'tst-inequal)
  1634. X
  1635. X;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1636. X
  1637. X(defun string-equal-less-white  (str1 str2)
  1638. X  " Returns t if the two strings are equal after ignoring whitespace."
  1639. X
  1640. X  (let  ()
  1641. X    (string-equal-less-regexp "\\s " str1 str2)
  1642. X  ) ; let
  1643. X) ; line-of-buffer
  1644. X
  1645. X
  1646. X;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1647. X
  1648. X(defun string-equal-less-regexp  (regexp str1 str2)
  1649. X  " Returns t if the two strings are equal after ignoring all substrings
  1650. X    that match regexp ."
  1651. X
  1652. X  (let  (start1 end1  start2 end2 token1 token2 success more1 more2)
  1653. X    (setq  success t more1 t more2 t)
  1654. X    (setq start1 (first-not-regexp regexp str1 0)); move to 1st non-white
  1655. X    (setq start2 (first-not-regexp regexp str2 0)); move to 1st non-white
  1656. X
  1657. X    (while (and more1 more2)
  1658. X      (progn
  1659. X     (setq end1 (string-match regexp str1 start1))
  1660. X     (setq end2 (string-match regexp str2 start2))
  1661. X     (if end1
  1662. X         (progn         ; end1 not nil 
  1663. X           (setq token1 (substring str1 start1 end1))
  1664. X           (setq start1 (first-not-regexp regexp str1 end1))
  1665. X           (if (not start1)  ; check for trailing delimiter only
  1666. X           (setq more1 nil))
  1667. X           ); progn
  1668. X          ;else
  1669. X         (progn
  1670. X           (setq token1 (substring str1 start1 nil));
  1671. X           (setq more1 nil)
  1672. X           ); progn
  1673. X     ); if
  1674. X     (if end2
  1675. X         (progn         ; end2 not nil 
  1676. X           (setq token2 (substring str2 start2 end2))
  1677. X           (setq start2 (first-not-regexp regexp str2 end2))
  1678. X           (if (not start2)  ; check for trailing delimiter only
  1679. X           (setq more2 nil))
  1680. X           ); progn
  1681. X          ;else
  1682. X         (progn
  1683. X           (setq token2 (substring str2 start2 nil));
  1684. X           (setq more2 nil)
  1685. X           ); progn
  1686. X     ); if
  1687. X;      (send-string-to-terminal "[")
  1688. X;        (send-string-to-terminal token1)
  1689. X;        (send-string-to-terminal "][")
  1690. X;        (send-string-to-terminal token2)
  1691. X;        (send-string-to-terminal "]")
  1692. X     (setq success (string-equal token1 token2))
  1693. X     (if (not success)
  1694. X         (setq more1 nil)) ; if failed then stop the loop
  1695. X      ); progn
  1696. X    ) ; while
  1697. X    (and (not more1) (not more2) success)
  1698. X  ) ; let
  1699. X) ; string-equal-less-white
  1700. X
  1701. X
  1702. X;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1703. X
  1704. X(defun first-not-regexp (regexp str sindex)
  1705. X  " Returns the index of the first char in string that does not match
  1706. X    regular expression. Returns nil if nothing doesn't match."
  1707. X
  1708. X  (let  (fm more string-is-nil)
  1709. X    (setq more t slen)
  1710. X    (setq slen (length str))
  1711. X    (if (equal 0 slen) ; test for a zero length string
  1712. X    nil
  1713. X    ; else
  1714. X        (progn
  1715. X      (setq string-is-nil nil)
  1716. X      (setq fm (string-match regexp str sindex)) ; start of match
  1717. X      (if (or (not fm) (< sindex fm)) (setq more nil)) ; found non-regexp
  1718. X;      (debug nil "Before while" fm sindex)
  1719. X      (while more
  1720. X        (progn
  1721. X          (setq sindex (match-end 0))
  1722. X          (if (>= sindex slen) 
  1723. X          (progn
  1724. X            (setq string-is-nil t)
  1725. X            (setq more nil)
  1726. X            )
  1727. X        ;else
  1728. X        (progn
  1729. X          (setq fm (string-match regexp str sindex))
  1730. X          (if (or (not fm) (< sindex fm)) (setq more nil))
  1731. X;          (debug nil "In while " fm sindex)
  1732. X        ); progn
  1733. X        ); if
  1734. X        ); progn
  1735. X      ); while
  1736. X      (if string-is-nil nil sindex)
  1737. X     ); progn
  1738. X    ); if
  1739. X  ) ; let
  1740. X) ; first-not-regexp
  1741. X
  1742. X
  1743. X
  1744. X
  1745. X; example hook usage
  1746. X;
  1747. X; (setq tst-equ-line-hook 'first-5)
  1748. X; (setq tst-equ-mark-hook 'great-mark)
  1749. X;
  1750. X; example line hook - only compares first 5 chars on a line
  1751. X;(defun first-5 ()
  1752. X;    (string-equal (substring tst-equ-line1 0 5) (substring tst-equ-line2 0 5))
  1753. X;)
  1754. X
  1755. X;example mark hook - only concerned with relative order of marks
  1756. X;(defun great-mark ()
  1757. X;    (> tst-equ-mark1 tst-equ-mark2)
  1758. X; )
  1759. X
  1760. X
  1761. X
  1762. SHAR_EOF
  1763. if test 3828 -ne "`wc -c < 'tst-inequal.el'`"
  1764. then
  1765.     echo shar: "error transmitting 'tst-inequal.el'" '(should have been 3828 characters)'
  1766. fi
  1767. fi
  1768. echo shar: "extracting 'tst-instrument.el'" '(5937 characters)'
  1769. if test -f 'tst-instrument.el'
  1770. then
  1771.     echo shar: "will not over-write existing file 'tst-instrument.el'"
  1772. else
  1773. sed 's/^X//' << \SHAR_EOF > 'tst-instrument.el'
  1774. X;;; tst-instrument
  1775. X;;; Copyright 1987 Richard Rosenthal
  1776. X;;; All rights reserved.
  1777. X
  1778. X(provide 'tst-instrument)
  1779. X(require 'tst-annotate)
  1780. X
  1781. X(defvar *tst-last-instrumented-line* 0
  1782. X  "Defined in instrument.el.  Used in the following functions:
  1783. X     tst-instrument-defun
  1784. X     tst-instrument-primitive")
  1785. X
  1786. X(defun tst-instrument ()
  1787. X  "The tst-instrument function creates a buffer containing a copy of
  1788. Xthe buffer in which the function was invoked.  All code in the copied
  1789. Xbuffer is then instrumented and compiled.  We are talking about
  1790. Xcompiling LISP code."
  1791. X  (interactive)
  1792. X  (let* ((old-buffer (buffer-name))
  1793. X     (instrumented-buffer
  1794. X      (get-buffer-create (concat old-buffer "-instrumented"))))
  1795. X    (save-excursion
  1796. X      (set-buffer instrumented-buffer)
  1797. X      (emacs-lisp-mode)
  1798. X      (erase-buffer)
  1799. X      (insert-buffer old-buffer)
  1800. X      (tst-ann-set-db nil)
  1801. X      (tst-instrument-region (point-min) (point-max))
  1802. X      (eval-current-buffer)
  1803. X      (message "Done"))))
  1804. X
  1805. X
  1806. X(defun tst-instrument-region (start end)
  1807. X  (interactive "r")
  1808. X  (save-restriction
  1809. X    (narrow-to-region start end)
  1810. X    (goto-char (point-min))
  1811. X    (or (looking-at "\\s( *defun\\b") (beginning-of-next-defun))
  1812. X    (while (< (point) (point-max))
  1813. X      (tst-instrument-defun)
  1814. X      (beginning-of-next-defun))))
  1815. X
  1816. X
  1817. X(defun tst-instrument-defun ()
  1818. X  (save-excursion
  1819. X    (save-restriction
  1820. X      (push-mark (point) 'nomsg)
  1821. X      (setq *tst-last-instrumented-line* (line-number))
  1822. X      (if (error-occurred (forward-sexp 1))
  1823. X      (progn
  1824. X        (goto-char (point-max))
  1825. X        nil)
  1826. X    (narrow-to-region (mark) (point))
  1827. X    (goto-char (point-min))
  1828. X    (down-list 1)
  1829. X    (next-sexp)            ;looking at defun
  1830. X    (beginning-of-next-sexp)    ;looking at function name
  1831. X    (let ((start (point))
  1832. X          end)
  1833. X      (forward-sexp 1)
  1834. X      (setq end (point))
  1835. X      (backward-sexp 1)
  1836. X      (message "Instrumenting (defun %s..." (buffer-substring start end))
  1837. X      )
  1838. X    (beginning-of-next-sexp)    ;looking at parameter list
  1839. X    (beginning-of-next-sexp)    ;looking at comment?
  1840. X    (if (looking-at "\\s\"")
  1841. X        (beginning-of-next-sexp))    ;looking at parameter list
  1842. X
  1843. X    ;; now looking at first statement in defun
  1844. X    (while (< (point) (point-max))
  1845. X      (cond
  1846. X       ((looking-at "\\s(")
  1847. X        (tst-instrument-function))
  1848. X
  1849. X       ;;inside a comment
  1850. X       ((nth 4 (parse-partial-sexp (point-min) (point) nil nil nil))
  1851. X        (end-of-line)
  1852. X        (next-sexp))
  1853. X
  1854. X       (t
  1855. X        (beginning-of-next-sexp))))
  1856. X    t))))
  1857. X
  1858. X
  1859. X(defun tst-instrument-function ()
  1860. X;;;at this point, I was definitly looking at a left "(".
  1861. X  (cond
  1862. X   ((tst-looking-at-prohibited-form-p)
  1863. X    (beginning-of-next-sexp))        ;do nothing, skip it
  1864. X
  1865. X   ((tst-looking-at-special-form-p)
  1866. X    (tst-instrument-primitive)        ;instrument around it
  1867. X    (tst-instrument-special-form))    ;try to go in it
  1868. X
  1869. X   (t
  1870. X    (tst-instrument-primitive)        ;instrument around it
  1871. X      (down-list 1))))            ;go in it
  1872. X
  1873. X(defun tst-looking-at-prohibited-form-p ()
  1874. X  (cond
  1875. X   ((looking-at "\\s( *interactive\\b") t)
  1876. X   ((looking-at "\\s( *quote\\b") t)
  1877. X   ((looking-at "\\s'\\s(") t)
  1878. X   (t nil)))
  1879. X
  1880. X(defun tst-looking-at-special-form-p ()
  1881. X  "List potential trouble makers in this function"
  1882. X  (cond
  1883. X   ((looking-at "\\s( *cond\\b") t)
  1884. X   ((looking-at "\\s( *function\\b") t)
  1885. X   ((looking-at "\\s( *let\\b") t)
  1886. X   ((looking-at "\\s( *progn\\b") t)
  1887. X   (t nil)))
  1888. X
  1889. X(defun tst-instrument-special-form ()
  1890. X  "Explain how to deal with known trouble makers in this function"
  1891. X  (cond
  1892. X   ((looking-at "\\s( *let\\b")        ;minor problem
  1893. X    (tst-instrument-let))
  1894. X   ((looking-at "\\s( *progn\\b")    ;no problem
  1895. X    (down-list 1))
  1896. X   (t                    ;skip forms I don't know about
  1897. X    (beginning-of-next-sexp))))
  1898. X
  1899. X(defun tst-instrument-primitive ()
  1900. X  (let ((start (line-number)))
  1901. X    (if (> start *tst-last-instrumented-line*)
  1902. X    (progn
  1903. X      (setq *tst-last-instrumented-line* start)
  1904. X      (insert "(tst-cover " (int-to-string start) " ")
  1905. X      (forward-sexp 1)
  1906. X      (insert ")")
  1907. X      (backward-char 1)
  1908. X      (backward-sexp 1)
  1909. X      (tst-ann-append start 'count '(0))))))
  1910. X
  1911. X
  1912. X(defun tst-instrument-let ()
  1913. X  (down-list 1)
  1914. X  (next-sexp)                ;looking at let
  1915. X  (beginning-of-next-sexp)        ;looking at parameter list
  1916. X  (forward-sexp 1)            ;skip parameters for now
  1917. X  (next-sexp))
  1918. X
  1919. X
  1920. X;;;----------------------------------------------------------------------------
  1921. X(defun tst-cover (id arg)
  1922. X  "Version 2:  for testing, display arg in mini-buffer while
  1923. Xmoving cursor around buffer"
  1924. X  (save-excursion
  1925. X    (goto-line id)
  1926. X    (re-search-forward "\\s(")
  1927. X    (message "function returns %s" (prin1-to-string arg))
  1928. X    (sit-for 2)
  1929. X    )
  1930. X  arg)
  1931. X
  1932. X(defun tst-cover (id arg)
  1933. X  "Version 1:  for testing, display id and arg in mini-buffer"
  1934. X  (message "tst-cover %d %s" id (prin1-to-string arg))
  1935. X  (sit-for 0)
  1936. X  arg)
  1937. X
  1938. X(defun tst-cover (id arg)
  1939. X  "Version 0:  for testing, does nothing"
  1940. X  arg)
  1941. X
  1942. X(defun tst-cover (id arg)
  1943. X  "The Real Thing:  uses annotation capabilities"
  1944. X  (tst-ann-inc id 'count)
  1945. X  (tst-ann-append id 'values (list arg))
  1946. X  arg)
  1947. X
  1948. X
  1949. X;;;============================================================================
  1950. X(defun beginning-of-next-defun ()
  1951. X  "This function finds LISP defun"
  1952. X  (if (= (point) (point-max))
  1953. X      nil
  1954. X    (forward-char 1)
  1955. X    (and (re-search-forward "\\s( *defun\\b" nil 'move 1)
  1956. X     (re-search-backward "\\s("))))
  1957. X
  1958. X(defmacro error-occurred (&rest body)
  1959. X  "As defined in mlsupport.el"
  1960. X  (list 'condition-case nil (cons 'progn (append body '(nil))) '(error t)))
  1961. X
  1962. X(defun line-number ()
  1963. X  "Return line number of current line.  Gives consistent results."
  1964. X  (count-lines-correctly 1 (point)))
  1965. X
  1966. X(defun count-lines-correctly (start end)
  1967. X  "Return number of newlines between START and END.  Gives
  1968. Xconsistent results."
  1969. X  (save-excursion
  1970. X    (save-restriction
  1971. X      (goto-char end)
  1972. X      (end-of-line)
  1973. X      (narrow-to-region start (point))
  1974. X      (goto-char (point-min))
  1975. X      (- (buffer-size) (forward-line (buffer-size))))))
  1976. X
  1977. X(defun next-sexp ()
  1978. X  (while (error-occurred (forward-sexp))
  1979. X    (forward-char 1))
  1980. X  (or (= (point) (point-max)) (backward-sexp)))
  1981. X
  1982. X(defun beginning-of-next-sexp ()
  1983. X  (forward-sexp 1)
  1984. X  (next-sexp))
  1985. SHAR_EOF
  1986. if test 5937 -ne "`wc -c < 'tst-instrument.el'`"
  1987. then
  1988.     echo shar: "error transmitting 'tst-instrument.el'" '(should have been 5937 characters)'
  1989. fi
  1990. fi
  1991. exit 0
  1992. #    End of shell archive
  1993.  
  1994.  
  1995. -- 
  1996.  
  1997. Rich $alz
  1998. Cronus Project, BBN Labs            rsalz@bbn.com
  1999. Moderator, comp.sources.unix            sources@uunet.uu.net
  2000.